package com.leetcode.array_matrix;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author Dennis Li
 * @date 2020/10/11 16:56
 */
public class RemoveCoveredIntervals_1288 {

    public int removeCoveredIntervals(int[][] intervals) {
        int count = intervals.length;
//        PriorityQueue<Integer> queue = new PriorityQueue<>(Comparator.comparingInt(o -> intervals[o][0]));

        Arrays.sort(intervals, Comparator.comparingInt(o -> o[0]));


        int i = intervals[0][0], j = intervals[0][1];

        for (int k = 1; k < intervals.length; k++) {
            int x = intervals[k][0], y = intervals[k][1];
            if (j >= y) count--;
            if (i == x && j <= y) count--;
            if (j < y) {
                i = x;
                j = y;
            }
        }

        return count;
    }

}
